package com.leo.entity;

import com.almasb.fxgl.core.math.FXGLMath;
import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.entity.EntityFactory;
import com.almasb.fxgl.entity.SpawnData;
import com.almasb.fxgl.entity.Spawns;
import com.almasb.fxgl.texture.Texture;
import com.leo.component.SayHelloComponent;
import com.leo.component.TankComponent;

/**
 * @Author: wangss
 * @CreateTime: 2023-06-05  23:25
 * @Description: TODO
 */
public class ImageEntityFactory implements EntityFactory {

    @Spawns("tank")
    public Entity createTank(SpawnData spawnData) {
        Texture texture = FXGL.texture("tank/tank.png");
        // 随机生成颜色
        Texture brighter = texture.multiplyColor(FXGLMath.randomColor()).brighter();
        return FXGL.entityBuilder(spawnData)
                .view(brighter)
                // 如果 TankComponent 中要使用 SayHelloComponent，则最好把 SayHelloComponent 加到前边
                .with(new SayHelloComponent())
                .with(new TankComponent())
                // 禁用组件的onUpdate方法，比较耗费性能
                .neverUpdated()
                .build();
    }
}
